<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>

							<li>
								商品名称：<input type="text" name="goodsName"/>
							</li>

							<li>
								商品状态：
								<select name="goodsStatus">
									<option value="">请选择</option>
									<option value="0">上架</option>
									<option value="1">下架</option>
								</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="business:integralGoods:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.editFull()" shiro:hasPermission="business:integralGoods:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:integralGoods:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:integralGoods:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:integralGoods:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:integralGoods:remove')}]];
		var undercarriageFlag = [[${@permission.hasPermi('business:integralGoods:undercarriage')}]];
		var shelvesFlag = [[${@permission.hasPermi('business:integralGoods:shelves')}]];
        var prefix = ctx + "business/integralGoods";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "积分商品",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'goodsId', 
					title : '积分商品ID',
					visible: false
				},
				{
					title: "序号",
					formatter: function (value, row, index) {
						return $.table.serialNumber(index);
					}
				},
				{
					field : 'companyId', 
					title : '公司ID',
					visible: false
				},
				{
					field : 'goodsName', 
					title : '商品名称'
				},
				{
					field : 'goodsCover', 
					title : '封面图',
					formatter: function (value, row, index) {
						return "<img class='img-thumbnail' width='65' height='65' src=" + value + ">";
					}
				},
				{
					field : 'inventory', 
					title : '库存',
					sortable: true
				},
				{
					field : 'marketPrice', 
					title : '市场价格',
					sortable: true
				},
				{
					field : 'costPrice', 
					title : '成本价格',
					sortable: true
				},
				{
					field : 'exchangeScore', 
					title : '兑换积分',
					sortable: true
				},
				{
					field : 'sendType', 
					title : '配送方式',
					formatter: function (value, row, index) {
						if (value == 0){
							return "公司自提"
						}
					}
				},
				{
					field : 'goodsStatus', 
					title : '商品状态',
					formatter: function (value, row, index) {
						if (value == 0){
							return "上架"
						}else if (value == 1) {
							return "下架"
						}
					}
				},
				{
					field : 'goodsSort', 
					title : '排序',
					visible: false,
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.editFull(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
						if (row.goodsStatus != 1) {
							actions.push('<a class="btn btn-primary btn-xs ' + undercarriageFlag + '" href="#" onclick="undercarriage(\'' + row.goodsId + '\')"><i class="fa fa-long-arrow-down"></i> 下架</a>');
						}else if(row.goodsStatus != 0){
							actions.push('<a class="btn btn-primary btn-xs ' + shelvesFlag + '" href="#" onclick="shelves(\'' + row.goodsId + '\')"><i class="fa fa-long-arrow-up"></i> 上架</a>');
						}
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

		/**
		 * 下架
		 * @param goodsId
		 */
		function undercarriage(goodsId) {
			$.modal.confirm("确认要下架该商品吗？", function () {
				$.operate.post(prefix + "/undercarriage", {"goodsId": goodsId});
			})
		}

		/**
		 * 上架
		 * @param goodsId
		 */
		function shelves(goodsId) {
			$.modal.confirm("确认要上架该商品吗？", function () {
				$.operate.post(prefix + "/shelves", {"goodsId": goodsId});
			})
		}
    </script>
</body>
</html>